/*******************************************************************************
 * Copyright (c) 2007 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.extensionpoints.transformation.validator;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;

import com.cea.papyrus.extensionpoints.transformation.Activator;

/**
 * Validator class for source model selection dialog
 */
public class FileSelectionValidator implements ISelectionStatusValidator {

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
	 */
	public IStatus validate(Object[] arg0) {

		if ((arg0 == null) || (arg0.length < 1)) {
			return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No selection.");
		}
		
		Object selection = arg0[0];
		if (! (selection instanceof IFile)) {
			
			return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The selection should be a file.");
		}
		
		return new Status(
				IStatus.OK
				, Activator.PLUGIN_ID
				, "Selection is valid");
	}
}
